import { waitApprovalAmount } from '@/service/approvalSetting'

const state = {
  approvalAmountData: {
    PI: 0,
    delivery_apply: 0,
    revoke_write_off: 0
  }
}

const mutations = {
  SET_APPROV_AMOUNT: (state, { type, amount }) => {
    state.approvalAmountData[type] = amount
  }
}

const actions = {
  async getAwaitApprovalAmount({ commit }, params) {
    const approvalTypeList = await waitApprovalAmount({ ...params, nodeHandleSystem: 'finance' })
    approvalTypeList.forEach(o => {
      commit('SET_APPROV_AMOUNT', { type: o.requestType, amount: o.total })
    })
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
